﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 理想漫反射模型
/// </summary>
public class Lambertian : Material
{
    Color albedo;
    public override bool scatter(Ray ray, HitRecord record, ref Color attaenuation, ref Ray scattered)
    {
        Vector3 target = record.p + record.normal + GetRandomPointInUnitSphere();
        scattered = new Ray(record.p, target - record.p);
        attaenuation = albedo;
        return true;
    }

    private Vector3 GetRandomPointInUnitSphere()
    {
        Vector3 p = 2f * new Vector3(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)) - Vector3.one;
        p = p.normalized * UnityEngine.Random.Range(0f, 1f);
        return p;
    }
    public Lambertian(Color a)
    {
        albedo = a;
    }
}
